<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/WEB-INF/common/hplus-css.jsp"%>
<link rel="shortcut icon" href="${path}/favicon.ico" rel="stylesheet">
<link href="${path}/assets/hplus/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="${path}/assets/hplus/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="${path}/assets/hplus/css/animate.css" rel="stylesheet">
<link href="${path}/assets/hplus/css/style.css?v=4.1.0" rel="stylesheet">
<link href="${path}/assets/hplus/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="${path}/assets/hplus/css/plugins/jsTree/style.min.css" rel="stylesheet">
<link href="${path}/assets/hplus/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
</head>
<body class="gray-bg">
     <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-content">
                         <form action="${path}/role/edit" class="form-horizontal m-t" id="roleForm" method="post">
                             <input id="id" name="id" type="hidden" value="${role.id}">
                             <div class="form-group">
                                <label class="col-sm-3 control-label">角色名称：</label>
                                <div class="col-sm-8">
                                    <input type="text" id="nameZh" name="nameZh" minlength="2" class="form-control" required=""  value="${role.nameZh}" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">标识：</label>
                                <div class="col-sm-8">
                                    <input type="text" id="nameEn" name="nameEn" class="form-control"  value="${role.nameEn}" readonly="readonly" />
								</div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">状态：</label>
                                <div class="col-sm-8">
                                     <select class="form-control" id="status" name="status">
                                        <option value="1" ${role.status == 1?"selected='selected'":""}>启用</option>
                                        <option value="0" ${role.status == 0?"selected='selected'":""}>禁用</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">权限：</label>
                                <div class="col-sm-8">
                                    <div id="using_json"></div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-3">
                                    <button class="btn btn-primary" id="update-btn" type="button">修改角色</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
     <%@include file="/WEB-INF/common/hplus-js.jsp"%>
    <!-- Peity -->
    <script src="${path}/assets/hplus/js/plugins/peity/jquery.peity.min.js"></script>
    <script src="${path}/assets/hplus/js/content.js"></script>
    <script src="${path}/assets/hplus/js/plugins/jsTree/jstree.min.js"></script>
    <!-- jqGrid -->
    <script src="${path}/assets/hplus/js/plugins/jqgrid/i18n/grid.locale-cn.js?0820"></script>
    <script src="${path}/assets/hplus/js/plugins/jqgrid/jquery.jqGrid.min.js?0820"></script>
    <script type="text/javascript">
    
	    $(function() {
	    	
	        $("#using_json").jstree({
	            "core": {
	            	'data' : function (obj, callback) {
	                    var jsonstr="[]";
	                    var jsonarray = eval('('+jsonstr+')');
	                    $.ajax({
	                    	type: "POST",
	                        url:"${path}/menu/querynews",
	                        data:{roleId:"${role.id}"},
	                        dataType:"json",
	                        async: false,
	                        success:function(result) {

	                        	var arrays = result.menus;
                        	 	var roleMenus = result.roleMenus;
                        	 	
	                            for(var i=0 ; i<arrays.length; i++) {
	                            	var arr = {};
	                            	arr["id"] = arrays[i].id;
                            		arr["parent"] = arrays[i].pid?arrays[i].pid:"#";
                            		arr["text"] = arrays[i].name;
	                            	for(var k=0;k<roleMenus.length; k++) {
	                            		if(arrays[i].id == roleMenus[k].id && (roleMenus[k].url != "#" || roleMenus[k].menuButton == "button")) {
	                            			arr["state"] = {"checked":true};
	                            			break;
	                            		} 
	                            	}
	                            	
	                                jsonarray.push(arr);
	                            }
	                        }
	                    });
	                    
	                    callback.call(this, jsonarray);
	                }
	            },
	            "checkbox" : {
	            	 "keep_selected_style" : false,
	                 "tie_selection":false
	            },
	            "plugins" : [ "wholerow", "checkbox" ]
	        });
	        
	    });
    
        $(document).ready(function () {
        	$("#roleForm").validate();
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
            $("#update-btn").click(function(){
            	
            	var valid = $("#roleForm").valid();
            	
            	if(valid) {
            		
            		parent.layer.msg('正在提交请稍候......', {icon: 16,time: 200000,shade : [0.5 , '#000' , true]});
            		///var nodes = new Array();
   
            		var nodes=$("#using_json").jstree("get_checked");
            	 	/* var data = {mensId: nodes};
           		 	formSubmit("roleForm",data); */
           		 	
           		 $("#roleForm").ajaxSubmit({
                     dataType: "json",
                     data:{mensId: nodes},
                     traditional: true,//必须指定为true
                     
                     
                     success: function (json) {
                         var code = json.code;
                         if (code == 0) {
                            
                             setTimeout(function () {
                                 window.location.reload();
                                 parent.layer.closeAll();
                             }, 1000);
                         } else {
                             layer.msg('发生错误:' + json.msg, {
                                 icon: 5
                             });
                         }
                     },
                     error: function () {
                         layer.msg('发生错误', {
                             icon: 5
                         });
                     }
                 });
            		
            	}else{
            		layer.msg("请填写完整信息！！！！", {
        				icon : 5
        			});
            	}
            });
        });
    </script>
</body>
</html>
